home *** CD-ROM | disk | FTP | other *** search
- UNIT Event;
-
- {+----------------------------------------------------------------------------+
- | |
- | HodgePodge: An example Apple IIGS Desktop application |
- | |
- | Written in 65816 assembler and APW C by the Apple IIGS Tools Team |
- | Translated to TML Pascal by TML Systems, Inc. |
- | Modified by Ben Koning for "Programmer's Introduction to the Apple IIGS" |
- | |
- | Copyright (c) 1986-87 by Apple Computer, Inc. |
- | Copyright (c) 1987 by TML Systems, Inc. |
- | |
- | -------------------------------- |
- | |
- | Pascal UNIT "EVENT.PAS" : Event loop and dispatching routine |
- | |
- +----------------------------------------------------------------------------+}
-
-
-
- INTERFACE
-
- USES
- HPIntfData, {HodgePodge Apple IIGS Toolbox Interface Units}
- HPIntfProc,
- HPIntfPdos,
-
- Globals, {HodgePodge Code Units}
- Dialog,
- Font,
- Paint,
- Window,
- Print,
- Menu;
-
-
-
- procedure MainEvent; {Main event handling loop which repeats until Quit}
-
-
-
- IMPLEMENTATION
-
-
-
- procedure DisableItems;
-
- {Private routine to disable (dim) certain menu titles}
-
- begin {of DisableItems}
- DisableMItem (SaveAsItem);
- DisableMItem (CloseItem);
- DisableMItem (PrintItem);
- DisableMItem (PageSetItem);
- end; {of DisableItems}
-
-
-
- procedure EnableItems;
-
- {Private routine to enable (undim) certain menu titles}
-
- begin {of EnableItems}
- EnableMItem (SaveAsItem);
- EnableMItem (CloseItem);
- EnableMItem (PrintItem);
- EnableMItem (PageSetItem);
- end; {of EnableItems}
-
-
-
- procedure DisableAll;
-
- {Private routine to disable all menu titles for Desk Accessory (DA)}
-
- begin {of DisableAll}
- SetMenuFlag ($0080,EditMenuID);
- DrawMenuBar;
- DisableItems;
- end; {of DisableAll}
-
-
-
- procedure SetUpForAppW;
-
- {Called if an application window (ours) is the frontmost window.
- Private routine.}
-
- begin {of SetUpForAppW}
- SetMenuFlag ($0080,EditMenuID);
- DrawMenuBar;
- EnableItems;
- end; {of SetUpForAppW}
-
-
-
- procedure SetUpForDAW;
-
- {Called if a Desk Accessory's window is the frontmost window. Private.}
-
- begin {of SetUpForDAW}
- DisableItems;
- EnableMItem (CloseItem);
- SetMenuFlag ($FF7F,EditMenuID);
- DrawMenuBar;
- end; {of SetUpForDAW}
-
-
-
- procedure CheckFrontW;
-
- {Check to whom the front window belongs to (us or a Desk Accessory (DA)),
- and if it belongs to us, whether it is appropriate to disable (dim) certain
- menu items (such as the Save item) or to enable them. Private routine.}
-
- var theWindow : GrafPortPtr;
- myDataHandle : WindDataH;
-
- begin {of CheckFrontW}
- theWindow := FrontWindow;
-
- if theWindow = lastWindow then
- Exit;
-
- if theWindow = nil then
- DisableAll
- else begin
- if GetSysWFlag (theWindow) = true then
- SetUpforDAW
- else begin
- SetUpforAppW;
- myDataHandle := WindDataH (GetWRefCon (theWindow));
- if myDataHandle^^.Flag = 1 then
- DisableMItem (SaveAsItem)
- end;
- end;
-
- lastWindow := theWindow;
- end; {of CheckFrontW}
-
-
-
- procedure DoActivate;
-
- {If the Activate event is indeed an activate instead of a deactivate
- then update menus based upon what the front window is. Private routine.}
-
- begin {of DoActivate}
- if BitAnd (Event.wmModifiers,ActiveFlag) <> 0 then
- CheckFrontW;
- end; {of DoActivate}
-
-
-
- procedure MainEvent;
-
- {Main event handling routine which loops until the Done flag is set by
- selection of the "Quit" item. We call the Window Manager's TaskMaster
- routine, which calls the Event Manager's GetNextEvent routine and
- handles window resize tracking/resizing, window movement tracking/resizing,
- window activiation (bringing to front by clicking on an inactive window),
- among other things. TaskMaster returns control to us when the user has
- clicked a window's GoAway check box, or when the user has selected a menu
- item, either with the mouse or with an equivalent Solid-Apple keystroke
- sequence.}
-
- var code : integer;
-
- begin {of MainEvent}
- Event.wmTaskMask := $1FFF; {Allow TaskMaster to do everything}
- Done := false; {Done flag will be set by Quit item}
-
- repeat
- CheckFrontW;
- code := TaskMaster (-1,Event);
- case code of
- ActivateEvt : DoActivate;
- wInGoAway : DoCloseItem;
- wInSpecial,
- wInMenuBar : DoMenu;
- end;
- until Done;
- end; {of MainEvent}
-
-
-
- END.
-